﻿using System.Collections.Generic;
using System.Linq;
using ClientOverflow.DataTransferObjects;

namespace ClientOverflow.ViewModels.KnowledgeSummaryViewModels
{
    public class TagActivityViewModel
    {
        public string TagName { get; private set; }
        public int NumOfQuestions { get; private set; }
        public int Votes { get; private set; }
        public double Ratio { get { return Votes == 0 ? 0 : NumOfQuestions / (double)Votes; } }

        public TagActivityViewModel(Tag tag, IEnumerable<IEnumerable<Question>> tagGroup)
        {
            TagName = tag.Name;
            var tagQuestions = tagGroup.SelectMany(questions => questions).Distinct();
            NumOfQuestions = tagQuestions.Count();
            Votes = tagQuestions
                .Sum(question => question.Answers.Sum(answer => answer.UpVotes.Count - answer.DownVotes.Count));
        }
    }
}